home *** CD-ROM | disk | FTP | other *** search
- Path: mail2news.demon.co.uk!genesis.demon.co.uk
- From: Lawrence Kirby <fred@genesis.demon.co.uk>
- Newsgroups: comp.lang.c
- Subject: Re: Help with C Date/Time Calc
- Date: Sat, 30 Mar 96 17:44:03 GMT
- Organization: none
- Message-ID: <828207843snz@genesis.demon.co.uk>
- References: <4irm8d$bev@dfw-ixnews5.ix.netcom.com> <4it4ru$h9c@fohnix.metronet.com> <1996Mar24.201410.14507@sq.com>
- Reply-To: fred@genesis.demon.co.uk
- X-NNTP-Posting-Host: genesis.demon.co.uk
- X-Newsreader: Demon Internet Simple News v1.27
- X-Mail2News-Path: genesis.demon.co.uk
-
- In article <1996Mar24.201410.14507@sq.com> msb@sq.com "Mark Brader" writes:
-
- >Keith Zawila (kzawila@ix.netcom.com) wrote:
- >> > I have the total number of seconds that have elapsed since 1/1/70,
- >> > and need to calculate the current date/time.
- >
- >Stan Milam (milam@fohnix.metronet.com) answered:
- >> Check your manual for time(), localtime(), strftime(), ctime(), gmtime(),
- >> and mktime(). ...
- >
- >Note that those functions work with an arithmetic type called time_t,
- >which represents calendar times (i.e. date and time) in a manner NOT
- >specified by the C standard. On UNIX systems, this manner happens to
- >be "the total number of seconds that have elapsed since 1/1/70". Keith
- >is probably using a UNIX system or he wouldn't have asked that particular
- >question; if so, Stan has answered it.
-
- Stan's answer needn't be taken as Unix specific e.g. consider:
-
- time_t timeval;
- struct tm tmbuf;
-
- tmbuf.tm_sec = seconds_since_1_1_70;
- tmbuf.tm_min = 0;
- tmbuf.tm_hour = 0;
- tmbuf.tm_mday = 1;
- tmbuf.tm_mon = 0;
- tmbuf.tm_year = 70;
- tmbuf.tm_isdst = -1;
-
- timeval = mktime(&tmbuf);
-
- The 2 issues here are:
-
- 1. Whether the time can be represented in a time_t value (you cn test the
- return code of mkttime).
-
- 2. Whether seconds_since_1_1_70 can be represented by an int since the
- struct tm members are ints. If not you can help it out by breaking things
- down a bit, say into seconds, minutes and days.
-
- --
- -----------------------------------------
- Lawrence Kirby | fred@genesis.demon.co.uk
- Wilts, England | 70734.126@compuserve.com
- -----------------------------------------
-